package com.firexxx.study.performancetest.scene;

import com.firexxx.study.util.chart.ChartUtil;
import lombok.Data;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 单个结果
 *
 * @author fireXXX
 * @date 2020/11/27 0:34
 **/
@Data
public class SingleResult implements IResult {

    private String name = "default";

    private List<Long> data = new ArrayList<>();

    private Long max = 0L;

    private Long min = 0L;

    public SingleResult(String name) {
        this.name = name;
    }

    public void calMax() {
        max = 0L;
        if (!CollectionUtils.isEmpty(data)) {
            max = data.stream().mapToLong(x -> x).max().getAsLong();
        }
    }

    public void calScalaMax(long rate) {
        calMax();
        data = data.stream()
                .map(item -> Math.round(item*rate*1.0/max))
                .collect(Collectors.toList());

        max = rate;
    }

    @Override
    public void show(String title) {
        calMax();
        ChartUtil.show(title, this);
    }

}